<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="author" content="Guillaume Laborde - Guillaume Lameyre" />
<link rel="stylesheet" media="screen" type="text/css" title="style" href="css/style.css" />
<title>ContactBook</title>
</head>

<body>

	<c:set var="account" value="${sessionScope.account}"></c:set>
	<c:if test="${empty account}">
		<c:redirect url="Index" />
	</c:if>
	
	<div id="mainframe">
		<c:import url="include/privateBanner.html" />
		<h1>Modifer le contact</h1>
		<div id="content">	
		
			<c:choose>
				<c:when test="${message == 'CONTACT_UPDATED_OK'}">
					<form action="Contact" method="POST" class="form">
						<table>
							<tr><td>Le contact a bien été modifié.</td></tr>
							<tr><td class="button"><input type="image" src="images/back.png" alt="Retour" /></td></tr>
						</table>
					</form>
				</c:when>
				<c:when test="${message == 'CONTACT_UPDATED_LASTNAME_FAIL'}">
					<p class="error">Le nom de famille du contact doit être renseigné.</p>
				</c:when>
				<c:when test="${message == 'CONTACT_UPDATED_FAIL'}">
					<p class="error">Le modification du contact a échouée.</p>
				</c:when>
			</c:choose>
				
			<c:if test="${message != 'CONTACT_UPDATED_OK'}">
				<jsp:useBean id="contact" class="contactbook.model.Contact" scope="request" />
				<form action="UpdateContact" method="POST" class="form">
					<table>
						<tr>
							<td>Prénom</td>
							<td><input type="text" name="firstName" id="firstName" value="<jsp:getProperty name="contact" property="firstName" />" /></td>
						</tr>
						<tr>
							<td>Nom</td>
							<td><input type="text" name="lastName" id="lastName" value="<jsp:getProperty name="contact" property="lastName" />" /></td>
						</tr>
						<tr>
							<td>Groupe</td>
							<td>
								<select name="group" id="group" />
									<option value="0" <c:if test="${group.id == 0}">selected="selected"</c:if>>Défaut</option>
									<c:forEach var="group" items="${requestScope.groups}">
										<jsp:useBean id="group" class="contactbook.model.Group" scope="page" />
										<option value="<jsp:getProperty name="group" property="id" />" <c:if test="${group.id == contact.group.id}">selected="selected"</c:if>><jsp:getProperty name="group" property="name" /></option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td>Email</td>
							<td><input type="text" name="email" id="email" value="<jsp:getProperty name="contact" property="email" />"/></td>
						</tr>
						<tr>
							<td>Téléphone</td>
							<td><input type="text" name="phoneNumber" id="phoneNumber" value="<jsp:getProperty name="contact" property="phoneNumber" />"/></td>
						</tr>
						<tr>
							<td>Adresse</td>
							<td><textarea name="address" id="address" cols="20" rows="4"><jsp:getProperty name="contact" property="address" /></textarea></td>
						</tr>
						<tr>
							<td>Code postal</td>
							<td><input type="text" name="zipCode" id="zipCode" value="<jsp:getProperty name="contact" property="zipCode" />" /></td>
						</tr>
						<tr>
							<td>Ville</td>
							<td><input type="text" name="town" id="town\" value="<jsp:getProperty name="contact" property="town" />" /></td>
						</tr>
						<tr>
							<td>Pays</td>
							<td><input type="text" name="country" id="country" value="<jsp:getProperty name="contact" property="country" />" /></td>
						</tr>
						<tr>
							<td>Situation familiale</td>
							<td>
								<select name="maritalStatus" id="maritalStatus" />
									<c:forEach var="maritalStatus" items="${requestScope.maritalStatus}">
											<option value="${maritalStatus}" <c:if test="${maritalStatus == requestScope.contact.maritalStatus}">selected="selected"</c:if>><c:out value="${maritalStatus}" /></option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td>Age</td>
							<td><input type="text" name="age" id="age" value="<jsp:getProperty name="contact" property="age" />" /></td>
						</tr>
						<tr>
							<td colspan="2" class="button"><input type="submit" name="submit" value="OK" /> <input type="submit" name="submit" value="Annuler" /></td>
						</tr>
					</table>
					<input type="hidden" name="contactId" value="<jsp:getProperty name="contact" property="id" />" />
				</form>
			</c:if>
		</div>
		<c:import url="include/bottom.html" />
	</div>

</body>
</html>